#REQUIRE PACKAGES ####
packages <- c("lmerTest", "dplyr", "readxl", "ggplot2", "tidyr", "stringr", "emmeans", "MASS", "parameters")
lapply(packages, require, character.only = TRUE)
#------------------------------------------------------------------------------------------#
#READ IN AND PREPARE THE DATA ####

#First setwd in RStudio to location of source file (must be saved together with data)

setwd("./spr2018")

spr <- lapply(dir(),read.csv)
spr1 <- Reduce(intersect, lapply(spr, colnames))
spr2 <- lapply(spr, function(x) x[spr1])
spr.df <- do.call("rbind", spr)
change44 <- which(spr.df$participant==444) #incorrectly entered a participant number
participant.column <- which(colnames(spr.df)=="participant")
spr.df[change44, participant.column] <- 44

setwd('..') #moves up to parent directory
p3 <- read.csv("00003_SPR_GPFeb2018_2018_feb_15_0914_4.csv")
p3$participant <- "3"

p3$frameRate <- as.character(p3$frameRate)
spr.df$participant <- as.character(spr.df$participant)
spr.df.full <- bind_rows(spr.df, p3)
spr.df.full <- filter(spr.df.full, TYPE!="PRAC") #filters out practice items

spr.df.full <- dplyr::select(spr.df.full, TYPE, question, PLAUSIBILITY, corr, RAND_NUM, NUMBER, IRI_0, IRI_1, IRI_2, IRI_3, IRI_4, IRI_5, IRI_6, IRI_7, IRI_8, IRI_9, IRI_10, IRI_11, IRI_12, IRI_13, key_resp_3.keys, key_resp_3.corr, participant, key_resp_3.rt)

bdata <- read.csv("./leap2018_updated.csv")
bdata <- bdata[,-1] #removes unnecessary row numbers
colnames(spr.df.full) <- toupper(colnames(spr.df.full))
bdata$PARTICIPANT <- as.character(bdata$PARTICIPANT)
spr.df <- left_join(bdata, spr.df.full)
#------------------------------------------------------------------------------------------#
#READ IN CTEST SCORES ####

ctest <- read_excel("new ctesr.xlsx")
ctest <- dplyr::select(ctest, PARTICIPANT, TOTAL)
ctest$PARTICIPANT <- na.omit(ctest$PARTICIPANT)
ctest$TOTAL <- na.omit(ctest$TOTAL)
ctest.trim <- ctest[-c(69:136),]
colnames(ctest.trim)[2] <- "CTEST"
ctest.trim$PARTICIPANT <- as.character(ctest.trim$PARTICIPANT)
spr.df.full <- left_join(spr.df, ctest.trim)
#------------------------------------------------------------------------------------------#
#CALCULATE OVERALL ACCURACY ####

questions <- filter(spr.df.full, QUESTION!="na" & !grepl("FILLER", spr.df$TYPE, ignore.case=TRUE))
problematic.questions <- c("1A", "1B", "1C", "1D", "4A", "4C", "6B", "6D", "9A", "9C", "10B", "10D")
questions <- filter(questions, !(NUMBER %in% problematic.questions))
mean(questions$KEY_RESP_3.CORR==1) * 100 #88.63%
#------------------------------------------------------------------------------------------#
#NUMBER OF PARTICIPANTS ####

length(unique(spr.df.full$PARTICIPANT)) #67
afr.df <- filter(spr.df.full, L1=="AFRIKAANS")
eng.df <- filter(spr.df.full, L1=="ENGLISH")
length(unique(afr.df$PARTICIPANT)) #33
length(unique(eng.df$PARTICIPANT)) #34
#------------------------------------------------------------------------------------------#
#ENG MEAN ACCURACY

questions %>%
	filter(L1=="ENGLISH") %>%
	summarise(acc = sum(KEY_RESP_3.CORR)/length(KEY_RESP_3.CORR) * 100) #88.47
#------------------------------------------------------------------------------------------#
#AFR MEAN ACCURACY

questions %>%
	filter(L1=="AFRIKAANS") %>%
	summarise(acc = sum(KEY_RESP_3.CORR)/length(KEY_RESP_3.CORR) * 100) #88.8
#------------------------------------------------------------------------------------------#
#COMPARE ENG & AFR MEAN ACCURACY

eng.test.items <- questions %>%
	filter(L1=="ENGLISH") %>%
	dplyr::select(KEY_RESP_3.CORR)
afr.test.items <- questions %>%
	filter(L1=="AFRIKAANS") %>%
	dplyr::select(KEY_RESP_3.CORR)
t.test(eng.test.items, afr.test.items) #p = 0.8
#------------------------------------------------------------------------------------------#
#ACCURACY PER BLOCK

spr.df.full$BLOCK <- ifelse(spr.df.full$RAND_NUM <= 21, 1, ifelse(spr.df.full$RAND_NUM >= 22 & spr.df.full$RAND_NUM <= 42, 2, ifelse(spr.df.full$RAND_NUM >= 43 & spr.df.full$RAND_NUM <= 63, 3, 4)))
questions.2 <- filter(spr.df.full, QUESTION!="na" & !grepl("filler", spr.df.full$TYPE, ignore.case=TRUE))
questions.2 <- filter(questions.2, !(NUMBER %in% problematic.questions))
questions.2$BLOCK <- as.factor(questions.2$BLOCK)
questions.2$L1 <- as.factor(questions.2$L1)
questions.2$PARTICIPANT <- as.factor(questions.2$PARTICIPANT)
questions.2$NUMBER <- as.factor(questions.2$NUMBER)
questions.2$KEY_RESP_3.CORR <- as.factor(questions.2$KEY_RESP_3.CORR)
model <- glm(KEY_RESP_3.CORR ~ BLOCK * L1, family=binomial, data=questions.2)
summary(model) 
#------------------------------------------------------------------------------------------#
#ACCURACY PER CONDITION (STRONG V WEAK GP)

model.2 <- glmer(KEY_RESP_3.CORR ~ L1 * TYPE + (1|PARTICIPANT) + (1|NUMBER), family=binomial, data=questions.2)
summary(model.2) #they do sig worse on the GP weak Qs compared to the GP strong qs, p = 0.058
#L1 English do sig worse on the GP Weak, p = 0.049
#------------------------------------------------------------------------------------------#
#ACCURACY PER CONDITION (IMPL V PLAUSIBLE GP)

model.3 <- glm(KEY_RESP_3.CORR ~ L1 * PLAUSIBILITY, family=binomial, data=questions.2)
summary(model.3) #They do worse on the Plaus qs, p = 0.01
#------------------------------------------------------------------------------------------#
#ACCURACY PER CONDITION (STRONG V WEAK GP * PLAUS)

model.4 <- glm(KEY_RESP_3.CORR ~ L1 * PLAUSIBILITY * TYPE, family=binomial, data=questions.2)
summary(model.4) 
#they do sig worse in Plaus condition, p < 0.0001
#------------------------------------------------------------------------------------------#
#ACCURACY STRONG GP QUESTIONS

strong.questions <- filter(questions.2, TYPE == "GP STRONG")
(contrasts(strong.questions$L1) <- c(-1,+1))
strong.questions$PLAUSIBILITY <- droplevels(strong.questions$PLAUSIBILITY)
(contrasts(strong.questions$PLAUSIBILITY) <- c(-1,+1))

model.5a <- glmer(KEY_RESP_3.CORR ~ L1 * PLAUSIBILITY + (1|PARTICIPANT), family=binomial, data=strong.questions)
model.5b <- glmer(KEY_RESP_3.CORR ~ L1 * PLAUSIBILITY + (1|NUMBER), family=binomial, data=strong.questions)
# AIC comparisons indicate model 5b is better

summary(model.5b) 
#they do sig worse in Plaus condition, p = 0.01

model.6 <- glmer(KEY_RESP_3.CORR ~ L1 * PLAUSIBILITY * CTEST + (1|PARTICIPANT) + (1|NUMBER), family=binomial, data=strong.questions)
summary(model.6) #this model does not converge
#ACCURACY WEAK GP QUESTIONS
weak.questions <- filter(questions.2, TYPE == "GP WEAK")
(contrasts(weak.questions$L1) <- c(-1,+1))
weak.questions$PLAUSIBILITY <- droplevels(weak.questions$PLAUSIBILITY)
(contrasts(weak.questions$PLAUSIBILITY) <- c(-1,+1))

model.5a <- glmer(KEY_RESP_3.CORR ~ L1 * PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), family=binomial, data=weak.questions)
summary(model.5a) 
#they do sig worse in Plaus condition, p = 0.01

model.6 <- glmer(KEY_RESP_3.CORR ~ L1 * PLAUSIBILITY * CTEST + (1|PARTICIPANT) + (1|NUMBER), family=binomial, data=weak.questions)
summary(model.6) #this model does not converge
#------------------------------------------------------------------------------------------#
#QUESTION ACCURACY ACCORDING TO AOA

questions.2$YOUNG <- ifelse(questions.2$AOA < 5, 1, 0)
questions.2$YOUNG <- as.factor(questions.2$YOUNG)
contrasts(questions.2$YOUNG) <- c(-1, +1)

questions.2.strong <- filter(questions.2, TYPE=="GP STRONG" & L1=="AFRIKAANS")

mod <- glmer(KEY_RESP_3.CORR ~ YOUNG + (1|PARTICIPANT) + (1|NUMBER), family="binomial", data=questions.2.strong)

mod <- lmer(KEY_RESP_3.RT ~ YOUNG + (1|PARTICIPANT) + (1|NUMBER), data=questions.2.strong)
#------------------------------------------------------------------------------------------#
#QUESTION ACCURACY PER PARTICIPANT

questions.2$KEY_RESP_3.CORR <- as.factor(questions.2$KEY_RESP_3.CORR)
participant.acc <- 	questions.2 %>%
					group_by(PARTICIPANT) %>%
					summarise(acc = mean(KEY_RESP_3.CORR==1)) %>%
					arrange(desc(acc))
#lowest score is 70%
#------------------------------------------------------------------------------------------#
#QUESTION ACCURACY PER ITEM

item.acc <- questions.2 %>%
			group_by(NUMBER) %>%
			summarise(acc = mean(KEY_RESP_3.CORR==1)) %>%
			arrange(desc(acc))
#some item scores were problematically low.
#have revisited questions for 1, 4, 6, 9 and 10
#------------------------------------------------------------------------------------------#
#CALCULATE BACKGROUND STATS

afr.exp <- which(afr.df$L1EXPOSURE + afr.df$L2EXPOSURE > 100) #removes the exposure numbers from people who misreport
eng.exp <- which(eng.df$L1EXPOSURE + eng.df$L2EXPOSURE > 100)
eng.L1EXPOSURE <- which(colnames(eng.df) == "L1EXPOSURE")
eng.L2EXPOSURE <- which(colnames(eng.df) == "L2EXPOSURE")
afr.L1EXPOSURE <- which(colnames(afr.df) == "L1EXPOSURE")
afr.L2EXPOSURE <- which(colnames(afr.df) == "L2EXPOSURE")
eng.df[eng.exp, c(eng.L1EXPOSURE,eng.L2EXPOSURE)] <- NA
afr.df[afr.exp, c(afr.L1EXPOSURE,afr.L2EXPOSURE)] <- NA

background.stats <- spr.df.full %>%
	group_by(L1) %>%
	dplyr::select(AGE, AOAL2, L1EXPOSURE, L2EXPOSURE, L2SPEAK, L2READ, L2COMP, CTEST) %>%	
	summarise_all(funs(mean, sd), na.rm=TRUE)

(range(afr.df$AOAL2)) #1-10
(range(afr.df$AGE)) #18-29
(range(eng.df$AGE)) #19-22

t.test(afr.df$AOAL2, eng.df$AOAL2)
t.test(afr.df$L2EXPOSURE, eng.df$L1EXPOSURE, na.rm=TRUE)
t.test(afr.df$L1EXPOSURE, eng.df$L2EXPOSURE, na.rm=TRUE)
t.test(afr.df$L2SPEAK, eng.df$L2SPEAK)
t.test(afr.df$L2READ, eng.df$L2READ)
t.test(afr.df$L2COMP, eng.df$L2COMP)
t.test(afr.df$CTEST, eng.df$CTEST)
#------------------------------------------------------------------------------------------#
#CALCULATE MEAN RTs

spr.df.full$FILLER <- as.factor(as.numeric(grepl("filler", spr.df.full$TYPE, ignore.case=TRUE)))
spr.df.full$IRI_total <- rowSums(spr.df.full[,c(35:43)], na.rm = TRUE)
mean.rt <- spr.df.full %>%
  dplyr::group_by(PARTICIPANT) %>%
  dplyr::summarise(mean.rt = mean(IRI_total, na.rm=TRUE))
mean.rt$PARTICIPANT <- as.factor(mean.rt$PARTICIPANT)
spr.df.full$PARTICIPANT <- as.factor(spr.df.full$PARTICIPANT)
spr.df.full <- left_join(spr.df.full, mean.rt)
spr.df.full$mean.rt.cent <- as.vector(scale(spr.df.full$mean.rt, scale=FALSE))
spr.df.full$PARTICIPANT <- as.factor(spr.df.full$PARTICIPANT)
#------------------------------------------------------------------------------------------#
#REMOVE EXTREME VALUES

short.finder <- function(x) {
	which(x < 0.1)
}

long.finder <- function(x) {
	which(x > 4)
}

which(colnames(spr.df.full)=="IRI_5") 	#35
which(colnames(spr.df.full)=="IRI_13") #43

#shorts <- lapply(spr.df.full[35:43], short.finder)
longs <- lapply(spr.df.full[35:43], long.finder)

subset <- spr.df.full[, c(35:43)]

for (i in 1:9){
  subset[unlist(longs[i], use.names = FALSE), i] <- NA
}

#for (i in 1:9){
#  subset[unlist(shorts[i], use.names = FALSE), i] <- NA
#}

spr.df.trimmed <- spr.df.full				  #copy a version of the df so we can write over it with our trimmed values
spr.df.trimmed[,c(35:43)] <- subset		#original RT columns are overwritten

na.per.segment <- spr.df.trimmed %>%
  dplyr::filter(TYPE!="FILLER", KEY_RESP_3.CORR==1) %>%
  dplyr::select(35:43) %>%
  dplyr::summarise_all(funs(sum(is.na(.)) / length(.)*100)) 

total.obs.L1 <- spr.df.trimmed %>%
  dplyr::filter(TYPE!="FILLER", KEY_RESP_3.CORR==1) %>%
  dplyr::group_by(L1, TYPE) %>%
  dplyr::select(35:43) %>%
  dplyr::count(.) #get total number of observations per type and L1

na.per.segment.L1 <- spr.df.trimmed %>%
  dplyr::filter(TYPE!="FILLER", KEY_RESP_3.CORR==1) %>%
  dplyr::group_by(L1, TYPE) %>%
  dplyr::select(35:43) %>%
  dplyr::summarise_all(funs(sum(is.na(.)))) # get total number of NAs

na.per.segment.L1$TOTAL <- rowSums(na.per.segment.L1[,c(3:11)])

total.obs.L1$TOTAL <- na.per.segment.L1$TOTAL
total.obs.L1$PERC <- (total.obs.L1$TOTAL/total.obs.L1$n)*100

rowSums(na.per.segment.L1[, c(3:11)])
  
(total.trimmed <- sum(na.per.segment[,(1:9)])) #7.3% data lost
#------------------------------------------------------------------------------------------#
#FIX PROBLEMATIC QS SO THEY ARE INCLUDED IN ANALYSIS
spr.df.trimmed.final <- spr.df.trimmed %>%
  mutate(KEY_RESP_3.CORR=replace(KEY_RESP_3.CORR, NUMBER %in% problematic.questions, 1)) 
#------------------------------------------------------------------------------------------#
#ADD IN ENGLISH EXPOSURE
spr.df.trimmed.final$ENG.EXP <- ifelse(spr.df.trimmed.final$L1=="ENGLISH", spr.df.trimmed.final$L1EXPOSURE, spr.df.trimmed.final$L2EXPOSURE)
#------------------------------------------------------------------------------------------#
#CHECK FOR REVIEWER ABOUT REDUCED RELATIVE PREDICATE IN STRONG GPS
spr.df.trimmed.final$ENG.EXP <- ifelse(spr.df.trimmed.final$L1=="ENGLISH", spr.df.trimmed.final$L1EXPOSURE, spr.df.trimmed.final$L2EXPOSURE)
#------------------------------------------------------------------------------------------#
#MAKE STRONG AND WEAK DFs

spr.strong <- filter(spr.df.trimmed.final, TYPE=="GP STRONG" & KEY_RESP_3.CORR == 1)
spr.weak <- filter(spr.df.trimmed.final, TYPE=="GP WEAK" & KEY_RESP_3.CORR == 1)
spr.weak$NUMBER<- as.factor(spr.weak$NUMBER)
spr.strong$NUMBER<- as.factor(spr.strong$NUMBER)
#------------------------------------------------------------------------------------------#
#MAKE ENG AND AFR STRONG AND WEAK DFs

spr.eng.strong <- filter(spr.strong, L1=="ENGLISH")
spr.afr.strong <- filter(spr.strong, L1=="AFRIKAANS")

spr.eng.weak <- filter(spr.weak, L1=="ENGLISH")
spr.afr.weak <- filter(spr.weak, L1=="AFRIKAANS")
#------------------------------------------------------------------------------------------#
#LOOK AT QUESTION RESPONSE TIMES
spr.qs <- filter(spr.df.trimmed.final, FILLER==0)

spr.qs.strong <- filter(spr.qs, TYPE=="GP STRONG")
mod <- lmer(log(KEY_RESP_3.RT)~ L1 * PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), data=spr.qs.strong)

spr.qs.weak <- filter(spr.qs, TYPE=="GP WEAK")
mod <- lmer(log(KEY_RESP_3.RT)~ L1 * PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), data=spr.qs.weak)
#------------------------------------------------------------------------------------------#
#BOTH GROUPS: LOG RTs spr.strong

#DIFF CONTRASTS
(contrasts(spr.strong$L1) <- ginv(t(contr.sum(2))))
spr.strong$PLAUSIBILITY <- droplevels(spr.strong$PLAUSIBILITY)
(contrasts(spr.strong$PLAUSIBILITY) <- ginv(t(contr.sum(2))))

#log.seg.5 	<- lmer(log(IRI_5) 	~ PLAUSIBILITY * L1 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong)
log.seg.6 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY * L1 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong)
log.seg.7 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY * L1 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong)
log.seg.8 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY * L1 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong)
log.seg.9 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY * L1 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong)
log.seg.10 	<- lmer(log(IRI_10) ~ PLAUSIBILITY * L1 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong)
log.seg.11 	<- lmer(log(IRI_11) ~ PLAUSIBILITY * L1 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong)
log.seg.12 	<- lmer(log(IRI_12) ~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong)
log.seg.13 	<- lmer(log(IRI_13) ~ PLAUSIBILITY * L1 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong)

log.seg.6a 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.strong)
log.seg.7a 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY||NUMBER), REML=TRUE, data=spr.strong)
log.seg.8a 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY||NUMBER), REML=TRUE, data=spr.strong)
log.seg.9a 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY||NUMBER), REML=TRUE, data=spr.strong)
log.seg.10a 	<- lmer(log(IRI_10) ~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY||NUMBER), REML=TRUE, data=spr.strong)
log.seg.11a 	<- lmer(log(IRI_11) ~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY||NUMBER), REML=TRUE, data=spr.strong)
log.seg.12a 	<- lmer(log(IRI_12) ~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY||NUMBER), REML=TRUE, data=spr.strong)
log.seg.13a 	<- lmer(log(IRI_13) ~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY||NUMBER), REML=TRUE, data=spr.strong)

#summary(log.seg.5)
summary(log.seg.6)
summary(log.seg.7)
summary(log.seg.8)
summary(log.seg.9)
summary(log.seg.10)
summary(log.seg.11)
summary(log.seg.12)
summary(log.seg.13)

strong_eng <- dplyr::filter(spr.strong, L1=="ENGLISH")
strong_afr <- dplyr::filter(spr.strong, L1=="AFRIKAANS")

log.seg.8.eng 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=strong_eng)
log.seg.8.afr 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=strong_afr)

log.seg.11.eng 	<- lmer(log(IRI_11) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=strong_eng)
log.seg.11.afr 	<- lmer(log(IRI_11) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=strong_afr)
#------------------------------------------------------------------------------------------#
#BOTH GROUPS: LOG RTs spr.weak

#DIFF CONTRASTS
(contrasts(spr.weak$L1) <- ginv(t(contr.sum(2))))
spr.weak$PLAUSIBILITY <- droplevels(spr.weak$PLAUSIBILITY)
(contrasts(spr.weak$PLAUSIBILITY) <- ginv(t(contr.sum(2))))

log.seg.5 	<- lmer(log(IRI_5) 	~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.weak)
log.seg.6 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY * L1 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.weak)
log.seg.7 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.weak)
log.seg.8 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY * L1 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.weak)
log.seg.9 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY * L1 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.weak)
log.seg.10 	<- lmer(log(IRI_10) ~ PLAUSIBILITY * L1 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.weak)
log.seg.11 	<- lmer(log(IRI_11) ~ PLAUSIBILITY * L1 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.weak)
log.seg.12 	<- lmer(log(IRI_12) ~ PLAUSIBILITY * L1 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.weak)
log.seg.13 	<- lmer(log(IRI_13) ~ PLAUSIBILITY * L1 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.weak)

log.seg.6a 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.weak)
log.seg.7a 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.weak)
log.seg.8a 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.weak)
log.seg.9a 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.weak)
log.seg.10a 	<- lmer(log(IRI_10) ~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.weak)
log.seg.11a 	<- lmer(log(IRI_11) ~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.weak)
log.seg.12a 	<- lmer(log(IRI_12) ~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.weak)
log.seg.13a 	<- lmer(log(IRI_13) ~ PLAUSIBILITY * L1 + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.weak)

AIC(log.seg.10)
AIC(log.seg.10a)

AIC(log.seg.11)
AIC(log.seg.11a)

AIC(log.seg.12)
AIC(log.seg.12a)

summary(log.seg.5)
summary(log.seg.6)
summary(log.seg.7)
summary(log.seg.8)
summary(log.seg.9)
summary(log.seg.10)
summary(log.seg.11)
summary(log.seg.12)
summary(log.seg.13)

log.seg.7.afr 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
log.seg.7.eng 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak)

log.seg.8.afr 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
log.seg.8.eng 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.eng.weak)
#------------------------------------------------------------------------------------------#
#SPR.STRONG AFR AOA

#DIFF CONTRASTS
spr.afr.strong$PLAUSIBILITY <- droplevels(spr.afr.strong$PLAUSIBILITY)
spr.afr.strong$PLAUSIBILITY <- factor(spr.afr.strong$PLAUSIBILITY, levels=c("IMPL", "PL"))
contrasts(spr.afr.strong$PLAUSIBILITY) <- c(-1,+1)
spr.afr.strong$AOAL2_scale <- as.vector(scale(spr.afr.strong$AOAL2, center=TRUE, scale=TRUE))
spr.afr.strong$ENG.EXP_scale <- as.vector(scale(spr.afr.strong$ENG.EXP, center=TRUE, scale=TRUE))

AOA.log.seg.5 	<- lmer(log(IRI_5) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.strong)
AOA.log.seg.6 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.strong)
AOA.log.seg.7 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.strong)
AOA.log.seg.8 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.strong)
AOA.log.seg.9 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.strong)
AOA.log.seg.10 	<- lmer(log(IRI_10) ~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.strong)
AOA.log.seg.11 	<- lmer(log(IRI_11) ~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.strong)
AOA.log.seg.12 	<- lmer(log(IRI_12) ~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.strong)
AOA.log.seg.13 	<- lmer(log(IRI_13) ~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.strong)

#AOA.log.seg.5 	<- lmer(log(IRI_5) 	~ PLAUSIBILITY * AOAL2_scale + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.strong)
AOA.log.seg.6 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY * AOAL2_scale + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.strong)
AOA.log.seg.7 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.strong)
AOA.log.seg.8 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY * AOAL2_scale + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.strong)
AOA.log.seg.9 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY * AOAL2_scale + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.strong)
AOA.log.seg.10 	<- lmer(log(IRI_10) ~ PLAUSIBILITY * AOAL2_scale + (1+PLAUSIBILITY|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), data=spr.afr.strong)
AOA.log.seg.11 	<- lmer(log(IRI_11) ~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1|NUMBER), data=spr.afr.strong)
AOA.log.seg.12 	<- lmer(log(IRI_12) ~ PLAUSIBILITY * AOAL2_scale + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), data=spr.afr.strong)
AOA.log.seg.13 	<- lmer(log(IRI_13) ~ PLAUSIBILITY * AOAL2_scale + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.strong)

#AOA.log.seg.5 	<- lmer(log(IRI_5) 	~ PLAUSIBILITY * AOAL2_scale + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.strong)
AOA.log.seg.6 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.afr.strong)
AOA.log.seg.7 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.afr.strong)
AOA.log.seg.8 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.afr.strong)
AOA.log.seg.9 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.afr.strong)
#AOA.log.seg.10 	<- lmer(log(IRI_10) ~ PLAUSIBILITY * AOAL2_scale + (1+PLAUSIBILITY|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), data=spr.afr.strong)
#AOA.log.seg.11 	<- lmer(log(IRI_11) ~ PLAUSIBILITY * AOAL2_scale + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), data=spr.afr.strong)
AOA.log.seg.12 	<- lmer(log(IRI_12) ~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), data=spr.afr.strong)
AOA.log.seg.13 	<- lmer(log(IRI_13) ~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.afr.strong)

#summary(AOA.log.seg.5)
summary(AOA.log.seg.6)
summary(AOA.log.seg.7)
summary(AOA.log.seg.8)
summary(AOA.log.seg.9)
summary(AOA.log.seg.10) #significant main effect of AOA
summary(AOA.log.seg.11)
summary(AOA.log.seg.12) #marginal Plaus*AOA interaction, p = 0.079
summary(AOA.log.seg.13)

#SPLIT ON MEDIAN AOA
spr.strong.afr.young <- filter(spr.afr.strong, AOAL2 < 5)
spr.strong.afr.old <- filter(spr.afr.strong, AOAL2 >= 5)

spr.afr.strong$YOUNG <- ifelse(spr.afr.strong$AOAL2 < 5, 1, 0)
spr.afr.strong$YOUNG <- as.factor(spr.afr.strong$YOUNG)
(contrasts(spr.afr.strong$YOUNG) <- ginv(t(contr.sum(2))))

AOA.log.young.seg.5 	<- lmer(log(IRI_5) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong.afr.young)
AOA.log.young.seg.6 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong.afr.young)
AOA.log.young.seg.7 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong.afr.young)
AOA.log.young.seg.8 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.strong.afr.young)
AOA.log.young.seg.9 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY + (1|PARTICIPANT), REML=TRUE, data=spr.strong.afr.young)
AOA.log.young.seg.10 	<- lmer(log(IRI_10) ~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.strong.afr.young)
AOA.log.young.seg.11 	<- lmer(log(IRI_11) ~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong.afr.young)
AOA.log.young.seg.12 	<- lmer(log(IRI_12) ~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong.afr.young)
AOA.log.young.seg.13 	<- lmer(log(IRI_13) ~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.strong.afr.young)

AOA.log.young.seg.5 	<- lmer(log(IRI_5) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.strong.afr.young)
AOA.log.young.seg.6 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.strong.afr.young)
AOA.log.young.seg.7 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.strong.afr.young)
AOA.log.young.seg.8 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.strong.afr.young)
AOA.log.young.seg.9 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY + (1|PARTICIPANT), REML=TRUE, data=spr.strong.afr.young)
AOA.log.young.seg.10 	<- lmer(log(IRI_10) ~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.strong.afr.young)
AOA.log.young.seg.11 	<- lmer(log(IRI_11) ~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.strong.afr.young)
AOA.log.young.seg.12 	<- lmer(log(IRI_12) ~ PLAUSIBILITY + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.strong.afr.young)
AOA.log.young.seg.13 	<- lmer(log(IRI_13) ~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.strong.afr.young)

summary(AOA.log.young.seg.5)
summary(AOA.log.young.seg.6)
summary(AOA.log.young.seg.7)
summary(AOA.log.young.seg.8)
summary(AOA.log.young.seg.9)
summary(AOA.log.young.seg.10)
summary(AOA.log.young.seg.11)
summary(AOA.log.young.seg.12)
summary(AOA.log.young.seg.13)

AOA.log.old.seg.5 	<- lmer(log(IRI_5) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong.afr.old)
AOA.log.old.seg.6 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.strong.afr.old)
AOA.log.old.seg.7 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.strong.afr.old)
AOA.log.old.seg.8 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong.afr.old)
AOA.log.old.seg.9 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.strong.afr.old)
AOA.log.old.seg.10 	<- lmer(log(IRI_10) ~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong.afr.old)
AOA.log.old.seg.11 	<- lmer(log(IRI_11) ~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong.afr.old)
AOA.log.old.seg.12 	<- lmer(log(IRI_12) ~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong.afr.old)
AOA.log.old.seg.13 	<- lmer(log(IRI_13) ~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.strong.afr.old)

summary(AOA.log.old.seg.5)
summary(AOA.log.old.seg.6)
summary(AOA.log.old.seg.7)
summary(AOA.log.old.seg.8)
summary(AOA.log.old.seg.9)
summary(AOA.log.old.seg.10)
summary(AOA.log.old.seg.11)
summary(AOA.log.old.seg.12)
summary(AOA.log.old.seg.13)
#------------------------------------------------------------------------------------------#
#SPR.STRONG ENG

#RESCALE BACKGROUND VARIABLES

spr.eng.strong.rescaled <- spr.eng.strong
(contrasts(spr.eng.strong.rescaled$L1) <- c(-1,+1))
spr.eng.strong.rescaled$PLAUSIBILITY <- droplevels(spr.eng.strong.rescaled$PLAUSIBILITY)
(contrasts(spr.eng.strong.rescaled$PLAUSIBILITY) <- c(-1,+1))

spr.eng.strong.rescaled$AOAL2 <- scale(spr.eng.strong.rescaled$AOAL2, center = TRUE, scale = TRUE)
spr.eng.strong.rescaled$CTEST <- scale(spr.eng.strong.rescaled$CTEST, center = TRUE, scale = TRUE)
spr.eng.strong.rescaled$L2EXPOSURE <- scale(spr.eng.strong.rescaled$L2EXPOSURE, center = TRUE, scale = TRUE)

eng.log.seg.5.a 	<- lmer(log(IRI_5) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong.rescaled)
eng.log.seg.6.a 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong.rescaled) #a is better than b
eng.log.seg.7.a 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong.rescaled) #a is better than b
eng.log.seg.8.a 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong.rescaled)
eng.log.seg.9.a 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong.rescaled)
eng.log.seg.10.a 	<- lmer(log(IRI_10) ~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong.rescaled)
eng.log.seg.11.a 	<- lmer(log(IRI_11) ~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong.rescaled)
eng.log.seg.12.a 	<- lmer(log(IRI_12) ~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong.rescaled)
eng.log.seg.13.a 	<- lmer(log(IRI_13) ~ PLAUSIBILITY + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong.rescaled) #a is better than b

#summary(eng.log.seg.5.a)
summary(eng.log.seg.6.a)
summary(eng.log.seg.7.a)
summary(eng.log.seg.8.a)
summary(eng.log.seg.9.a)
summary(eng.log.seg.10.a)
summary(eng.log.seg.11.a)
summary(eng.log.seg.12.a)
summary(eng.log.seg.13.a)

eng.log.seg.5.b 	<- lmer(log(IRI_5) 	~ PLAUSIBILITY + AOAL2 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong)
eng.log.seg.6.b 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY + AOAL2 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong)
eng.log.seg.7.b 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY + AOAL2 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong)
eng.log.seg.8.b 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY + AOAL2 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong)
eng.log.seg.9.b 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY + AOAL2 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong)
eng.log.seg.10.b 	<- lmer(log(IRI_10) ~ PLAUSIBILITY + AOAL2 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong)
eng.log.seg.11.b 	<- lmer(log(IRI_11) ~ PLAUSIBILITY + AOAL2 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong)
eng.log.seg.12.b 	<- lmer(log(IRI_12) ~ PLAUSIBILITY + AOAL2 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong)
eng.log.seg.13.b 	<- lmer(log(IRI_13) ~ PLAUSIBILITY + AOAL2 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=FALSE, data=spr.eng.strong)

summary(eng.log.seg.5.b)
summary(eng.log.seg.6.b)
summary(eng.log.seg.7.b)
summary(eng.log.seg.8.b)
summary(eng.log.seg.9.b)
summary(eng.log.seg.10.b)
summary(eng.log.seg.11.b)
summary(eng.log.seg.12.b)
summary(eng.log.seg.13.b)

AIC(eng.log.seg.6.a, eng.log.seg.6.b) #6b is better
AIC(eng.log.seg.7.a, eng.log.seg.7.b) #7a is better
AIC(eng.log.seg.8.a, eng.log.seg.8.b) #8a is better
AIC(eng.log.seg.9.a, eng.log.seg.9.b) #9b is better
AIC(eng.log.seg.10.a, eng.log.seg.10.b) #10a is better
AIC(eng.log.seg.11.a, eng.log.seg.11.b) #11a is better
AIC(eng.log.seg.12.a, eng.log.seg.12.b) #12a is better

eng.log.seg.6.c 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY * AOAL2 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.strong)
eng.log.seg.7.c 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY * AOAL2 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.strong)
eng.log.seg.8.c 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY * AOAL2 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.strong)
eng.log.seg.9.c 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY * AOAL2 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.strong)
eng.log.seg.10.c 	<- lmer(log(IRI_10) ~ PLAUSIBILITY * AOAL2 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.strong)
eng.log.seg.11.c 	<- lmer(log(IRI_11) ~ PLAUSIBILITY * AOAL2 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.strong)
eng.log.seg.12.c 	<- lmer(log(IRI_12) ~ PLAUSIBILITY * AOAL2 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.strong)
eng.log.seg.13.c 	<- lmer(log(IRI_13) ~ PLAUSIBILITY * AOAL2 + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.strong)

summary(eng.log.seg.5.c)
summary(eng.log.seg.6.c)
summary(eng.log.seg.7.c)
summary(eng.log.seg.8.c)
summary(eng.log.seg.9.c)
summary(eng.log.seg.10.c)
summary(eng.log.seg.11.c)
summary(eng.log.seg.12.c)
summary(eng.log.seg.13.c)

AIC(eng.log.seg.6.b, eng.log.seg.6.c) #6b is better
AIC(eng.log.seg.7.a, eng.log.seg.7.c) #7a is better
AIC(eng.log.seg.8.a, eng.log.seg.8.c) #8a is better
AIC(eng.log.seg.9.b, eng.log.seg.9.c) #9b is better
AIC(eng.log.seg.10.a, eng.log.seg.10.c) #10a is better
AIC(eng.log.seg.11.a, eng.log.seg.11.c) #11a is better
AIC(eng.log.seg.12.a, eng.log.seg.12.c) #12a is better
#------------------------------------------------------------------------------------------#
#SPR.WEAK ENG

#RESCALE BACKGROUND VARIABLES

spr.eng.weak.rescaled <- spr.eng.weak
spr.eng.weak.rescaled$AOAL2 <- scale(spr.eng.weak.rescaled$AOAL2, center = TRUE, scale = TRUE)
spr.eng.weak.rescaled$CTEST <- scale(spr.eng.weak.rescaled$CTEST, center = TRUE, scale = TRUE)
spr.eng.weak.rescaled$L2EXPOSURE <- scale(spr.eng.weak.rescaled$L2EXPOSURE, center = TRUE, scale = TRUE)

spr.eng.weak.rescaled$PLAUSIBILITY <- droplevels(spr.eng.weak.rescaled$PLAUSIBILITY)
(contrasts(spr.eng.weak.rescaled$PLAUSIBILITY) <- c(-1,+1))
spr.eng.weak.rescaled$AOAL2_scale <- scale(spr.eng.weak.rescaled$AOAL2, center=TRUE, scale=TRUE)

eng.log.seg.5 	<- lmer(log(IRI_5) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak)
eng.log.seg.6 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak)
eng.log.seg.7 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak)
eng.log.seg.8 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak)
eng.log.seg.9 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak)
eng.log.seg.10 	<- lmer(log(IRI_10) ~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak)
eng.log.seg.11 	<- lmer(log(IRI_11) ~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak)
eng.log.seg.12 	<- lmer(log(IRI_12) ~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak)
eng.log.seg.13 	<- lmer(log(IRI_13) ~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak)

eng.log.seg.5 	<- lmer(log(IRI_5) 	~ PLAUSIBILITY * AOAL2 * CTEST * L2EXPOSURE + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak.rescaled)
eng.log.seg.6 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY * AOAL2 * CTEST * L2EXPOSURE + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak.rescaled)
eng.log.seg.7 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY * AOAL2 * CTEST * L2EXPOSURE + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak.rescaled)
eng.log.seg.8 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY * AOAL2 * CTEST * L2EXPOSURE + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak.rescaled)
eng.log.seg.9 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY * AOAL2 * CTEST * L2EXPOSURE + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak.rescaled)
eng.log.seg.10 	<- lmer(log(IRI_10) ~ PLAUSIBILITY * AOAL2 * CTEST * L2EXPOSURE + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak.rescaled)
eng.log.seg.11 	<- lmer(log(IRI_11) ~ PLAUSIBILITY * AOAL2 * CTEST * L2EXPOSURE + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak.rescaled)
eng.log.seg.12 	<- lmer(log(IRI_12) ~ PLAUSIBILITY * AOAL2 * CTEST * L2EXPOSURE + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak.rescaled)
eng.log.seg.13 	<- lmer(log(IRI_13) ~ PLAUSIBILITY * AOAL2 * CTEST * L2EXPOSURE + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.eng.weak.rescaled)

summary(eng.log.seg.5)
summary(eng.log.seg.6)
summary(eng.log.seg.7)
summary(eng.log.seg.8)
summary(eng.log.seg.9)
summary(eng.log.seg.10)
summary(eng.log.seg.11)
summary(eng.log.seg.12)
summary(eng.log.seg.13)
#------------------------------------------------------------------------------------------#
#SPR.WEAK AFR AOA

#DIFF CONTRASTS
spr.afr.weak$PLAUSIBILITY <- droplevels(spr.afr.weak$PLAUSIBILITY)
(contrasts(spr.afr.weak$PLAUSIBILITY) <- c(-1,+1))
spr.afr.weak$AOAL2_scale <- as.vector(scale(spr.afr.weak$AOAL2, center=TRUE, scale=TRUE))
spr.afr.weak$ENG.EXP_scale <- as.vector(scale(spr.afr.weak$ENG.EXP, center=TRUE, scale=TRUE))

AOA.log.seg.5 	<- lmer(log(IRI_5) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.6 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.7 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.8 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.9 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.10 	<- lmer(log(IRI_10) ~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.11 	<- lmer(log(IRI_11) ~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.12 	<- lmer(log(IRI_12) ~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.13 	<- lmer(log(IRI_13) ~ PLAUSIBILITY + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)

AOA.log.seg.5 	<- lmer(log(IRI_5) 	~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.6 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.7 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.8 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY * AOAL2_scale + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.9 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY * AOAL2_scale + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.10 	<- lmer(log(IRI_10) ~ PLAUSIBILITY * AOAL2_scale + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.11 	<- lmer(log(IRI_11) ~ PLAUSIBILITY * AOAL2_scale + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.12 	<- lmer(log(IRI_12) ~ PLAUSIBILITY * AOAL2_scale + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.13 	<- lmer(log(IRI_13) ~ PLAUSIBILITY * AOAL2_scale + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak)

AOA.log.seg.5 	<- lmer(log(IRI_5) 	~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.6 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.7 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.8 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.9 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.10 	<- lmer(log(IRI_10) ~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.11 	<- lmer(log(IRI_11) ~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.12 	<- lmer(log(IRI_12) ~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.afr.weak)
AOA.log.seg.13a 	<- lmer(log(IRI_13) ~ PLAUSIBILITY * AOAL2_scale + (1|PARTICIPANT) + (1+PLAUSIBILITY|NUMBER), REML=TRUE, data=spr.afr.weak)

summary(AOA.log.seg.5)
summary(AOA.log.seg.6)
summary(AOA.log.seg.7)
summary(AOA.log.seg.8)
summary(AOA.log.seg.9)
summary(AOA.log.seg.10)
summary(AOA.log.seg.11)
summary(AOA.log.seg.12)
summary(AOA.log.seg.13) #no effects of AOA

spr.afr.weak.young <- filter(spr.afr.weak, AOAL2 < 5)
spr.afr.weak.old <- filter(spr.afr.weak, AOAL2 >= 5)

AOA.log.seg.5 	<- lmer(log(IRI_5) 	~ PLAUSIBILITY  + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.young)
AOA.log.seg.6 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY  + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.young)
AOA.log.seg.7 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY  + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.young)
AOA.log.seg.8 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY  + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.young)
AOA.log.seg.9 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY  + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.young)
AOA.log.seg.10 	<- lmer(log(IRI_10) ~ PLAUSIBILITY  + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.young)
AOA.log.seg.11 	<- lmer(log(IRI_11) ~ PLAUSIBILITY  + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.young)
AOA.log.seg.12 	<- lmer(log(IRI_12) ~ PLAUSIBILITY  + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.young)
AOA.log.seg.13 	<- lmer(log(IRI_13) ~ PLAUSIBILITY  + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.young)

AOA.log.seg.5 	<- lmer(log(IRI_5) 	~ PLAUSIBILITY  + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.old)
AOA.log.seg.6 	<- lmer(log(IRI_6) 	~ PLAUSIBILITY  + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.old)
AOA.log.seg.7 	<- lmer(log(IRI_7) 	~ PLAUSIBILITY  + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.old)
AOA.log.seg.8 	<- lmer(log(IRI_8) 	~ PLAUSIBILITY  + (1|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.old)
AOA.log.seg.9 	<- lmer(log(IRI_9) 	~ PLAUSIBILITY  + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.old)
AOA.log.seg.10 	<- lmer(log(IRI_10) ~ PLAUSIBILITY  + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.old)
AOA.log.seg.11 	<- lmer(log(IRI_11) ~ PLAUSIBILITY  + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.old)
AOA.log.seg.12 	<- lmer(log(IRI_12) ~ PLAUSIBILITY  + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.old)
AOA.log.seg.13 	<- lmer(log(IRI_13) ~ PLAUSIBILITY  + (1+PLAUSIBILITY|PARTICIPANT) + (1|NUMBER), REML=TRUE, data=spr.afr.weak.old)
#------------------------------------------------------------------------------------------#
#MAKE SOME PLOTS

source("summarySE_fun.r")

#MAKE LONG VERSION OF DF
spr.trimmed.long <- gather(spr.df.trimmed.final, REGION, RT, 35:43)
spr.trimmed.long <- dplyr::select(spr.trimmed.long, PARTICIPANT, L1, TYPE, PLAUSIBILITY, REGION, RT)
strong.long <- filter(spr.trimmed.long, TYPE=="GP STRONG")
weak.long <- filter(spr.trimmed.long, TYPE=="GP WEAK")

spr.afr.strong.long <- gather(spr.afr.strong, REGION, RT, 35:43)

#COMPUTE SUMMARY STATISTICS FOR PLOTTING
df.plot.strong <- summarySE(data=strong.long, measurevar="RT", groupvars=c("REGION","L1", "PLAUSIBILITY"), na.rm=TRUE,
                      conf.interval=.95, .drop=TRUE)
df.plot.weak <- summarySE(data=weak.long, measurevar="RT", groupvars=c("REGION","L1", "PLAUSIBILITY"), na.rm=TRUE,
                            conf.interval=.95, .drop=TRUE)

df.afr.strong <- summarySE(data=spr.afr.strong.long, measurevar = "RT", groupvars = c("REGION", "YOUNG", "PLAUSIBILITY"), na.rm = TRUE,
                           conf.interval = .95, .drop=TRUE)
							
#MANIPULATE REGION COLUMN TO GET SEGMENTS INTO THE RIGHT ORDER
df.plot.strong$REGION <- gsub("IRI_", "", df.plot.strong$REGION)
df.plot.strong$REGION <- as.numeric(df.plot.strong$REGION)
df.plot.strong <- arrange(df.plot.strong, REGION)
df.plot.weak$REGION <- gsub("IRI_", "", df.plot.weak$REGION)
df.plot.weak$REGION <- as.numeric(df.plot.weak$REGION)
df.plot.weak <- arrange(df.plot.weak, REGION)

df.afr.strong$REGION <- gsub("IRI_", "", df.afr.strong$REGION)
df.afr.strong$REGION <- as.numeric(df.afr.strong$REGION)
df.afr.strong <- arrange(df.afr.strong, REGION)

#PLOTTING
df.plot.strong <- filter(df.plot.strong, REGION!=5)
strong.plot <-ggplot(df.plot.strong, aes(x = factor(REGION), y = RT, group = PLAUSIBILITY)) + 
  geom_line(aes(linetype=PLAUSIBILITY))+
  geom_point()+
  labs(color = "Plausibility") +
  scale_linetype_discrete(labels = c("Implausible", "Plausible")) +
  geom_errorbar(width=.1, aes(ymin=RT-ci, ymax=RT+ci)) +
  facet_grid(L1 ~ .)

strong.plot + 
  scale_x_discrete(breaks = c("6", "7", "8", "9", "10", "11", "12", "13"), labels = c("beer", "imported", "from", "Europe", "pleased", "all", "the", "customers")) +
  xlab("Region") +
  ylab("RT in seconds") +
  ggtitle("Reading Times for Adjunct-Clause Items")

weak.plot <-ggplot(df.plot.weak, aes(x = factor(REGION), y = RT, group = PLAUSIBILITY)) + 
  geom_line(aes(linetype=PLAUSIBILITY))+
  geom_point()+
  labs(color = "Plausibility") +
  scale_linetype_discrete(labels = c("Implausible", "Plausible")) +
  geom_errorbar(width=.1, aes(ymin=RT-ci, ymax=RT+ci))+
  facet_grid(L1 ~ .)

weak.plot + scale_x_discrete(breaks = c("5", "6", "7", "8", "9", "10", "11", "12", "13"), labels = c("report", "about", "the", "budget", "would", "start", "an", "important", "debate")) +
  xlab("Region")+
  ylab("RT in seconds") +
  ggtitle("Reading Times for Complement-Clause Items")

df.afr.strong <- filter(df.afr.strong, REGION!=5)
AoA.plot <-ggplot(df.afr.strong, aes(x = factor(REGION), y = RT, group=interaction(YOUNG,PLAUSIBILITY), colour = PLAUSIBILITY)) + 
  geom_line(aes(linetype=YOUNG))+
  geom_point()+
  labs(color = "Plausibility") +
  scale_color_manual(labels = c("Implausible", "Plausible"), values = c("#e41a1c", "#377eb8")) +
  geom_errorbar(width=.1, aes(ymin=RT-ci, ymax=RT+ci)) 

AoA.plot + scale_x_discrete(breaks = c("6", "7", "8", "9", "10", "11", "12", "13"), labels = c("beer", "imported", "from", "Europe", "pleased", "all", "the", "customers")) +
  xlab("Region")+
  ylab("RT in seconds") +
  scale_y_log10(limits = c(0.4,1.3), breaks = seq(0.4,1.3,0.1)) +
  ggtitle("Reading Times for Adjunct-Clause Items in Early vs Later Acquirers")
#------------------------------------------------------------------------------------------#
#PLAUSIBILITY RATINGS
pratings <- read_excel("Plausibility rating (Responses).xlsx")

#GP STRONG SENTENCES
strong.pratings <- pratings[,c(22:41)]
strong.impls <- seq(1, by = 2, len = 10)
strong.pls <- seq(2, by = 2, len = 10)
strong.impls.pratings <- strong.pratings[, strong.impls]
strong.pls.pratings <- strong.pratings[, strong.pls]
mean(colMeans(strong.impls.pratings))
mean(colMeans(strong.pls.pratings))
t.test(colMeans(strong.impls.pratings),colMeans(strong.pls.pratings))

#GP WEAK SENTENCES
weak.pratings <- pratings[,c(2:21)]
weak.pls <- c(1, 3, 5, 7, 8, 10, 12, 14, 16, 18)
weak.impls <- c(2, 4, 6, 9, 11, 13, 15, 17, 19, 20)
weak.impls.pratings <- weak.pratings[, weak.impls]
weak.pls.pratings <- weak.pratings[, weak.pls]
mean(colMeans(weak.impls.pratings))
mean(colMeans(weak.pls.pratings))
t.test(colMeans(weak.impls.pratings),colMeans(weak.pls.pratings))
#------------------------------------------------------------------------------------------#